000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. PRJADDFS.
000250 AUTHOR. John Willis.
000300*
000400* PMD 0.01
000401*  COPYRIGHT (C) 2012 COHERENT LOGIC DEVELOPMENT LLC
000402*
000403*  PRJADDFS.COB: ADD RECORDS TO PROJECTS FILE (FULL-SCREEN I/O)
000500*   $Id: PRJADDFS.COB 5 2012-06-18 17:24:10Z chocolatejollis38@gmail.com $
000550*
000600 ENVIRONMENT DIVISION.
000700 INPUT-OUTPUT SECTION.
000800 FILE-CONTROL.
000850
000900		COPY "PRJSELCT.COB".
000950		COPY "CTRLSLCT.COB".
001500
001600 DATA DIVISION.
001700 FILE SECTION.
001800
001850 		COPY "PRJFD.COB".
002600		COPY "CTRLFD.COB".
002650
002700 WORKING-STORAGE SECTION.
002710 01 ENTRY-OK	PIC 9 VALUE 0.
002720 77 STATUS-MSG	PIC X(50).
002725 77 ERROR-MSG	PIC X(80).
002726 77 UPPER-ALPHA	PIC X(26) VALUE
002727	  "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
002728 77 LOWER-ALPHA	PIC X(26) VALUE
002729    "abcdefghijklmnopqrstuvwxyz".
002730 77 OK-TO-WRITE	PIC X VALUE " ".
002732 77 CONTINUE-MSG  PIC X(30) VALUE "OK TO WRITE? (Y/N)".
002735
002740 SCREEN SECTION.
002741
002742		COPY "SCPRJADD.COB".
002800
002900 PROCEDURE DIVISION.
003000 PROGRAM-BEGIN.
003100		OPEN I-O PROJECT-FILE.
003150		MOVE "TAB for next field, ENTER to write and exit."
003160		  TO STATUS-MSG.
003170		MOVE SPACE TO ERROR-MSG.
003200     	PERFORM MAIN-PROCESS.
003250	   	CLOSE PROJECT-FILE.
003300
003400 PROGRAM-DONE.
003500     	STOP RUN.
003510
003520 PROGRAM-EXIT.
003530		EXIT PROGRAM.
003600
003700 MAIN-PROCESS.
003800     	PERFORM INIT-PROJECT-RECORD.
003900	   	PERFORM ENTER-PROJECT-FIELDS.
003950		PERFORM CONFIRM-WRITE.
003951
003952 CONFIRM-WRITE.
003960		INSPECT OK-TO-WRITE
003961		  CONVERTING	LOWER-ALPHA
003962		  TO		UPPER-ALPHA.
003963
003964		IF OK-TO-WRITE = "Y"
004000	   	  WRITE PROJECT-RECORD
004050		  PERFORM WRITE-PROJECT-CONTROL
004060		ELSE
004070		IF OK-TO-WRITE = "N"
004080		  CLOSE CONTROL-FILE
004090		ELSE
004095		  MOVE 0 TO ENTRY-OK
004096		  MOVE "PLEASE CHOOSE Y OR N" TO ERROR-MSG
004098		  PERFORM DO-SCREEN UNTIL ENTRY-OK = 1.
004100
004200 INIT-PROJECT-RECORD.
004300     	MOVE SPACE TO PROJECT-RECORD.
004400	   	MOVE ZEROES TO PROJECT-NUMBER.
004500
004600 ENTER-PROJECT-FIELDS.
004610		PERFORM GET-PROJECT-NUMBER.
004611		PERFORM DO-SCREEN UNTIL ENTRY-OK = 1.
004612
004615 DO-SCREEN.
004620		DISPLAY ADD-RECORD-SCREEN.
005100		ACCEPT ADD-RECORD-SCREEN.
005200		PERFORM VALIDATE-ENTRY.
005300
007000 GET-PROJECT-NUMBER.
007010		OPEN I-O CONTROL-FILE.
007100     	MOVE 1 TO CONTROL-KEY.
007110		READ CONTROL-FILE RECORD WITH LOCK
007120		  INVALID KEY
007130		  DISPLAY "ERROR READING CONTROL RECORD".
007140		COMPUTE PROJECT-NUMBER = LAST-PROJECT-NUMBER + 1.
007150		MOVE PROJECT-NUMBER TO LAST-PROJECT-NUMBER.
007160
007170 WRITE-PROJECT-CONTROL.
007180		REWRITE CONTROL-RECORD WITH LOCK
007190		  INVALID KEY
007200		  DISPLAY "ERROR WRITING CONTROL RECORD".
007300	   	CLOSE CONTROL-FILE.
007400
007500 VALIDATE-ENTRY.
007600		MOVE 1 TO ENTRY-OK.
007700
007800		INSPECT PROJECT-NAME
007900		  CONVERTING 	LOWER-ALPHA
008000		  TO		UPPER-ALPHA.
008100
008200		IF PROJECT-NAME = SPACES
008300			MOVE 0 TO ENTRY-OK
008400			MOVE "PROJECT NAME IS REQUIRED" TO ERROR-MSG.
008500
008600		INSPECT PROJECT-DESCRIPTION
008700		  CONVERTING	LOWER-ALPHA
008800		  TO		UPPER-ALPHA.
008900
009000		IF CUSTOMER-NUMBER = ZEROES
009100		 	MOVE 0 TO ENTRY-OK
009200			MOVE "CUSTOMER NUMBER CANNOT BE ZERO"
009300			 TO ERROR-MSG.
009400
009500		IF DUE-DATE = " 0/00/0000"
009600			MOVE 0 TO ENTRY-OK
009700			MOVE "DUE DATE MUST BE SPECIFIED"
009800 		  	  TO ERROR-MSG.
009900
